package com.thinkfit.jy.activity;

import android.view.View;
import android.view.ViewGroup;

import com.common.lib.constant.EventBusEvent;
import com.common.lib.manager.DataManager;
import com.thinkfit.jy.R;
import com.thinkfit.jy.utils.SportsStatusBarViewUtils;
import com.thinkfit.jy.utils.ThemeUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;

/**
 * 主题选择
 */
public class SwitchMainStyleActivity extends MainActivity {

    private int switchMainNum = 6;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_switch_main_style;
    }

    public void init() {
        setViewsOnClickListener(R.id.ll_sport_back);
        int mainStyle = DataManager.Companion.getInstance().getMainStyle();
        if (mainStyle == 3) {
//            setBackground(R.id.rootView, R.drawable.app_bg_xm);
            setImage(R.id.ivHome, R.drawable.app_home_xm);
        }
        resetDate();
        int currentStyle = DataManager.Companion.getInstance().getMainStyle();
        for (int i = 0; i < switchMainNum; ++i) {
            ViewGroup view = findViewById(
                    getResources().getIdentifier("flStyle" + i, "id", getPackageName())
            );
            view.setOnClickListener(this);

//            if (mainStyle == 3) {
//                view.setBackgroundResource(currentStyle == i ?
//                        R.drawable.shape_88ffffff_5 : R.drawable.shape_2bffffff_5);
//            } else {
//                view.setBackgroundResource(currentStyle == i ?
//                        R.drawable.shape_4b494d_stroke_2e2d2e_6 : R.drawable.shape_121212_stroke_2e2d2e_6);
//            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        setBackground(R.id.rootView, ThemeUtils.getInstance().getMainTheme());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            // Technogym Theme  科学技术
            case R.id.ll_sport_back:
                finish();
                break;
            case R.id.flStyle0:
//                DataManager.Companion.getInstance().saveMainStyle(0);
//                openActivity(MainActivity.class);
//                finishAllActivity();
                DataManager.Companion.getInstance().saveMainStyle(ThemeUtils.THEME_MAIN);
                DataManager.Companion.getInstance().saveMainTheme(ThemeUtils.THEME_MAIN);
                SportsStatusBarViewUtils.getInstance().invaliView();
                finishAllActivity();
                openActivity(MainActivity.class);
                break;
            case R.id.flStyle1:
                // audi theme  奥迪 主题
//                DataManager.Companion.getInstance().saveMainStyle(1);
//                openActivity(MainADActivity.class);
//                finishAllActivity();
                DataManager.Companion.getInstance().saveMainStyle(ThemeUtils.THEME_PINK);
                DataManager.Companion.getInstance().saveMainTheme(ThemeUtils.THEME_PINK);
                SportsStatusBarViewUtils.getInstance().invaliView();
                finishAllActivity();
                openActivity(MainActivity.class);
                break;
            case R.id.flStyle2:
                // BMW theme  宝马 主题
                DataManager.Companion.getInstance().saveMainStyle(ThemeUtils.THEME_LANDSCAPE);
                DataManager.Companion.getInstance().saveMainTheme(ThemeUtils.THEME_LANDSCAPE);
                SportsStatusBarViewUtils.getInstance().invaliView();
                finishAllActivity();
                openActivity(MainActivity.class);
//                DataManager.Companion.getInstance().saveMainStyle(2);
//                openActivity(MainBMWActivity.class);
//                finishAllActivity();
                break;
            case R.id.flStyle3:
                // 小米主题
                DataManager.Companion.getInstance().saveMainStyle(3);
                openActivity(MainXMActivity.class);
                finishAllActivity();
                break;
            case R.id.flStyle4:
                DataManager.Companion.getInstance().saveMainStyle(ThemeUtils.THEME_DRAGON_BOAT_FESTIVAL);
                DataManager.Companion.getInstance().saveMainTheme(ThemeUtils.THEME_DRAGON_BOAT_FESTIVAL);
                SportsStatusBarViewUtils.getInstance().invaliView();
                finishAllActivity();
                openActivity(MainActivity.class);
                break;
            case R.id.flStyle5:
                DataManager.Companion.getInstance().saveMainStyle(ThemeUtils.THEME_FIRE_PROTECTION);
                DataManager.Companion.getInstance().saveMainTheme(ThemeUtils.THEME_FIRE_PROTECTION);
                SportsStatusBarViewUtils.getInstance().invaliView();
                finishAllActivity();
                openActivity(MainActivity.class);
                break;
        }
    }


    protected void showBottomUI() {

    }

    @Override
    public boolean isMainActivity() {
        return false;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceive(HashMap<String, Object> map) {
        if (map == null) {
            return;
        }
        if (map.containsKey(EventBusEvent.TIME_CHANGE)) {
            resetDate();
        } else {
            super.onReceive(map);
        }
    }
}